// pages/explosives/explosives.js
import baseuser from '~/utils/users.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    baostart: 1,
    lab1: [{
        title: '快团团'
      },
      {
        title: '群接龙'
      },
      {
        title: '其他'
      }
    ],
    lab1active: "快团团",
    lab2: [{
        title: '抖音'
      },
      {
        title: '快手'
      },
      {
        title: '天猫'
      },
      {
        title: '京东'
      },
      {
        title: '拼多多'
      },
      {
        title: '其他'
      },
    ],
    active2: 0,
    lab2active: "抖音",
    option1: [],
    option2: [],
    optionvalue1: '',
    optionvalue2: '',

    pages: 1,
    indexlist: [],
    salesVolume:'',
    brokerage:'',
    synthesis: 1,
    collect:0,
    browse:0,
    synthesis1: 1,
    collect1:0,
    browse1:0,
  },
  chongzhi() {
    this.setData({
        synthesis: 0,
        collect:0,
        browse: 0
    })
},
collstart(){
  if (this.data.collect == 0) {
    console.log();
      this.chongzhi()
      this.setData({
        salesVolume:'true',
        collect: 1

      })
      this.gatallcomp()

  } else if(this.data.collect == 1) {
      this.chongzhi()
      this.setData({
        salesVolume:'false',
          collect: 2
      })
      this.gatallcomp()

  }else if(this.data.collect == 2){
      this.chongzhi()
      this.setData({
        salesVolume:'true',
          collect: 0
      })
      this.gatallcomp()

  }
},
browsestart(){
  if (this.data.browse == 0) {
      this.chongzhi()
      this.setData({
        salesVolume:'',
        brokerage:'true',
          browse: 1
      })
      console.log(this.data.brokerage);
      this.gatallcomp()
  } else if(this.data.browse == 1) {
      this.chongzhi()
      this.setData({
        salesVolume:'',
        brokerage:'false',
          browse: 2
      })
      console.log(this.data.brokerage);

      this.gatallcomp()
  }else if(this.data.browse == 2){
      this.chongzhi()
      this.setData({
        salesVolume:'',
        brokerage:'true',
          browse: 0
      })
      console.log(this.data.brokerage);
      this.gatallcomp()
  }
},
  async onclikzong() {
    if (this.data.synthesis == 0) {
        this.chongzhi()
        this.setData({
            synthesis: 1,
            optionvalue1: '',
        })
        this.gatallcomp()

    } else {
        this.chongzhi()
        this.setData({
          // optionvalue1: '',
            synthesis: 0,
        })
    }
},
collstart1(){
  if (this.data.collect1 == 0) {
    console.log();
  
      this.setData({
        salesVolume1:'true',
        collect1: 1

      })
      this.gatallcomp1()

  } else if(this.data.collect1 == 1) {
       this.setData({
        salesVolume1:'false',
          collect1: 2
      })
      this.gatallcomp1()

  }else if(this.data.collect1 == 2){
       this.setData({
        salesVolume1:'true',
          collect1: 0
      })
      this.gatallcomp1()

  }
},
browsestart1(){
  if (this.data.browse1 == 0) {
       this.setData({
        salesVolume1:'',
        brokerage1:'true',
          browse1: 1
      })
      console.log(this.data.brokerage1);
      this.gatallcomp1()
  } else if(this.data.browse1 == 1) {
       this.setData({
        salesVolume1:'',
        brokerage1:'false',
          browse1: 2
      })
      console.log(this.data.brokerage1);

      this.gatallcomp1()
  }else if(this.data.browse1 == 2){
       this.setData({
        salesVolume1:'',
        brokerage1:'true',
          browse1: 0
      })
      console.log(this.data.brokerage1);
      this.gatallcomp1()
  }
},
  async onclikzong1() {
    if (this.data.synthesis1 == 0) {
         this.setData({
            synthesis1: 1,
            optionvalue2: '',
        })
        this.gatallcomp1()

    } else {
         this.setData({
          // optionvalue1: '',
            synthesis1: 0,
        })
    }
},
  scrollbind(items) {
    console.log('actt', items.currentTarget.dataset.select)
    this.setData({
      active2: items.currentTarget.dataset.select,
    })
    if(this.active2==1){
this.setData({
 })
 this.gatallcomp()
    }
  },
  naveback() {
    wx.navigateBack()
  },
  nextdetail(e) {
    // console.log('e',e.currentTarget.dataset.proid.proId);
    wx.navigateTo({
      url: `../details/details?id=${e.currentTarget.dataset.proid.id}`,
    })
  },
  gotoExplosivesSearch() {
    wx.navigateTo({
      url: '/search/explosivesSearch/explosivesSearch',
    })
  },
  selectchanges(item) {
    console.log(item.currentTarget.dataset.changes)
    this.setData({
      baostart: item.currentTarget.dataset.changes
    })
    if (this.data.baostart == 2) {

      this.setData({
        lab2active: this.data.lab2active
      })
      console.log('222', this.data.lab2active);
      this.gatallcomp1()
    }else if(this.data.baostart == 1){
      this.setData({
        lab1active: this.data.lab1active
      })
      console.log('222', this.data.lab1active);
      this.gatallcomp()
    }

  },

  tabsonChange2(items) {
    console.log('items.detail.title',items);
    this.setData({
      lab2active: items.detail.title
    })
    this.gatallcomp1()
  },
  tabsonChange1(items) {
     this.setData({
      lab1active: items.detail.title
    })
    this.gatallcomp()
  },

  async getfenlei() {
    let resdata = await baseuser.profirst()
    let newdata = resdata.data.result
    for (const i in newdata) {
      newdata[i].text = newdata[i].name
      newdata[i].value = newdata[i].name
    }
    this.setData({
      option1: newdata,
      option2: newdata
    })
  },
  async gatallcomp() {
    let reqdata = {
      "channelType": this.data.baostart,
      "current": this.data.pages,
      "pageSize": "10",
      "appName": this.data.lab1active,
      "salesVolume":this.data.salesVolume,
      "brokerage": this.data.brokerage,
      "category": this.data.optionvalue1
    }
    console.log('reqdata', reqdata);
    let resdata = await baseuser.manyConditions(reqdata)
    console.log('resdata', resdata)
    if (resdata.code == 200) {
      this.setData({
        indexlist: resdata.data.result.records
      })
    } else {
      wx.showToast({
        title: '查询失败',
        icon: 'none',
        duration: 2000
      })
    }
  },
  async gatallcomp1() {
    let reqdata = {
      "channelType": this.data.baostart,
      "current": this.data.pages,
      "pageSize": "10",
      "appName": this.data.lab2active,
      "salesVolume": this.data.salesVolume1,
      "brokerage": this.data.brokerage1,
      "category": this.data.optionvalue2
    }
    let resdata = await baseuser.manyConditions(reqdata)
    console.log('resdata', resdata)
    if (resdata.code == 200) {
      this.setData({
        indexlist: resdata.data.result.records
      })
    } else {
      wx.showToast({
        title: '查询失败',
        icon: 'none',
        duration: 2000
      })
    }
  },
  dropchange1(items) {
    this.setData({
      optionvalue1: items.detail,
      synthesis: 0,

    })
    console.log('items.detail', this.data.optionvalue1);
 
    this.gatallcomp()
  },
  dropchange2(items) {
    console.log('items.detail', items.detail);

    this.setData({
      optionvalue2: items.detail,
      synthesis1: 0,

    })
    this.gatallcomp1()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let Bartop = (0, wx.getMenuButtonBoundingClientRect)().top;
    let BarHeight = (0, wx.getMenuButtonBoundingClientRect)().height;

    console.log(wx.getMenuButtonBoundingClientRect())
    this.setData({
      settop: Bartop + BarHeight * 1.5
    })
    this.getfenlei()
    this.gatallcomp()
  },
  onChange(items) {
    console.log(items)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})